package com.czmh.etc.onlinepubsys.utils;

import java.security.MessageDigest;

public class SignUtils {

	private static final String ALGORITHM_MD5 = "MD5";
	private static final String CHARSET_UTF_8 = "UTF-8";

	public static String md5(String source) {
		try {
			MessageDigest md5 = MessageDigest.getInstance(ALGORITHM_MD5);
			byte[] md5byte = md5.digest(source.getBytes(CHARSET_UTF_8));
			StringBuffer strHexString = new StringBuffer();
			for (int i = 0; i < md5byte.length; i++) {
				String hex = Integer.toHexString(0xff & md5byte[i]);
				if (hex.length() == 1) {
					strHexString.append('0');
				}
				strHexString.append(hex);
			}
			return strHexString.toString();
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}

	}
}
